package rozetka.pageObjects;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import rozetka.ReportWriter;

public class OrderingPage {
	WebDriver driver;
	private static final By fieldForUserName = By
			.xpath("/html/body/div/div/section/div[2]/div/div/div/form/section/div/div/div/div/div[2]/input");
	private static final By fieldForUserCity = By
			.xpath("/html/body/div/div/section/div[2]/div/div/div/form/section/div/div/div/div[2]/div[2]/div/div/input");
	private static final By fieldForUserPhone = By
			.xpath("/html/body/div/div/section/div[2]/div/div/div/form/section/div/div/div/div[3]/div[2]/div/input[2]");
	private static final By fieldForUserEmail = By
			.xpath("/html/body/div/div/section/div[2]/div/div/div/form/section/div/div/div[2]/div[2]/input");
	private static final By buttonForwardToOrder = By
			.xpath("//*[@id='step_contacts']/div/div[1]/div[3]/div/span/button");

	public OrderingPage(WebDriver driver) {

		this.driver = driver;
	}

	public void fillUsersName(String userName) {
		driver.findElement(fieldForUserName).sendKeys(userName);
	}

	public void fillUserCity(String UserCity) {
		driver.findElement(fieldForUserCity).sendKeys(UserCity);

	}

	public void fillUserPhone(String UserPhone) {
		new Actions(driver)
				.moveToElement(driver.findElement(fieldForUserPhone)).click()
				.perform();
		driver.findElement(fieldForUserPhone).sendKeys(UserPhone);
	}

	public void fillUserEmail(String UserEmail) {
		driver.findElement(fieldForUserEmail).sendKeys(UserEmail);
	
	}

	public boolean isSuccessOrder() {
		WebElement phoneInput = driver.findElement(By.id("reciever_phone"));
		String colorBefore = phoneInput.getCssValue("background-color");
		ReportWriter.info("Before " + colorBefore);
		driver.findElement(buttonForwardToOrder).click();
		String colorAfter = phoneInput.getCssValue("background-color");
		ReportWriter.info("After " + colorAfter);
		return colorAfter.equals(colorBefore);
	}

}
